package com.isunland.managesystem.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PhoneNumberUtil {

  /**
   * 判断手机号格式是否正确
   */
  public boolean judgePhoneNumber(String number) {
    // 手机 号码判断
    Pattern phone = Pattern.compile("1[3|5|7|8|][0-9]{9}");
    Matcher match = phone.matcher(number);
    if (!match.matches()) {
      return false;
    }
    return true;
  }

  /**
   * 判断固话格式是否正确
   */
  public boolean judgeTellPhone(String tellPhone) {
    // 带有区号的固话，例如长途电话；如北京的固话以010开头，010-12345678
    Pattern call1 = Pattern.compile("0[0-9][0-9]{9}"); // 12位的固话
    Matcher match1 = call1.matcher(tellPhone);
    Pattern call2 = Pattern.compile("0[0-9][0-9]{8}"); // 11位的固话
    Matcher match2 = call2.matcher(tellPhone);
    if (!match1.matches() || !match2.matches()) {
      return false;
    }

    Pattern call3 = Pattern.compile("0[0-9][0-9]");
    String dial = tellPhone.substring(0, 3);
    Matcher match3 = call3.matcher(dial);
    if (!match3.matches() && tellPhone.length() != 8) {
      return false;
    }
    return true;
  }
}
